//
//  ClinicInvenDetailVC.m
//  XinTaiPub
//
//  Created by rzhyios on 2018/5/31.
//  Copyright © 2018年 rzhy. All rights reserved.
//

#import "ClinicInvenDetailVC.h"
#import "Patient.h"
#import "Config.h"
#import "ClinicClnvenCell.h"

@interface ClinicInvenDetailVC ()<UITableViewDelegate,UITableViewDataSource>
{
    Patient *_patient;
    NSArray *_dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSString *totalValueStr;


@end

@implementation ClinicInvenDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.dataSource = self;
    _patient = [Patient sharedPatient];
    [self.tableView registerNib:[UINib nibWithNibName:@"ClinicClnvenCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ClinicClnvenCell"];
    [self getZymrqdlb];
}

#pragma mark - 门诊每日清单详情
- (void)getZymrqdlb {
    NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary *param = @{@"id" : @(_patient.id),@"amt" : self.amt,@"date" : self.fyrq};
    [HTTPSTool POSTRequestWithPath:XHUserMzmrqd cookie:cookie params:param success:^(NSDictionary * _Nonnull JSON) {
        XHLog(@"住院每日清单列表 -> JSON: %@", JSON);
        _dataArray = JSON[@"data"][@"list"];
        self.totalValueStr = JSON[@"data"][@"totalAmt"];
        NSLog(@"%@",self.totalValueStr);
        [_tableView reloadData];
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return _dataArray.count;
    }else{
        return 1;
    }
    return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ClinicClnvenCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ClinicClnvenCell"];
    NSDictionary *dict = _dataArray[indexPath.row];
    switch (indexPath.section) {
        case 0:
            {
                cell.projectNameLabel.textColor = [UIColor redColor];
                cell.priceLabel.textColor = [UIColor redColor];
                cell.countLabel.textColor = [UIColor redColor];
                cell.totalValuLabel.textColor = [UIColor redColor];
                cell.projectNameLabel.text = @"项目名称";
                cell.priceLabel.text = @"单价";
                cell.countLabel.text = @"数量";
                cell.totalValuLabel.text = @"总价";
                cell.projectNameLabel.font = [UIFont systemFontOfSize:15];
                cell.priceLabel.font = [UIFont systemFontOfSize:15];
                cell.countLabel.font = [UIFont systemFontOfSize:15];
                cell.totalValuLabel.font = [UIFont systemFontOfSize:15];
            }
            break;
        case 1:
        {
            cell.projectNameLabel.text = dict[@"fymc"];
            cell.priceLabel.text = dict[@"fydj"];
            cell.countLabel.text = dict[@"fysl"];
            cell.totalValuLabel.text = dict[@"zjje"];
            cell.projectNameLabel.font = [UIFont systemFontOfSize:12];
            cell.priceLabel.font = [UIFont systemFontOfSize:12];
            cell.countLabel.font = [UIFont systemFontOfSize:12];
            cell.totalValuLabel.font = [UIFont systemFontOfSize:12];
            cell.projectNameLabel.textColor = [UIColor blackColor];
            cell.priceLabel.textColor = [UIColor blackColor];
            cell.countLabel.textColor = [UIColor blackColor];
            cell.totalValuLabel.textColor = [UIColor blackColor];
        }
            break;
        case 2:
        {
            cell.projectNameLabel.text = @"总价";
            cell.priceLabel.text = @"";
            cell.countLabel.text = @"";
            cell.totalValuLabel.text = self.totalValueStr;
             cell.projectNameLabel.font = [UIFont systemFontOfSize:15];
        }
            break;
            
        default:
            break;
    }
    
    
    return cell;
}




@end
